package work;

import com.rabbitmq.client.*;
import util.ConncetionUtil;

import java.io.DataInput;
import java.io.IOException;

public class Consumer {
    public static final String QUEUENAME="zfz";

    public static void main(String[] args) throws Exception{
        Connection connection = ConncetionUtil.getConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUENAME,false,false,false,null);
        channel.basicQos(1);
        channel.basicConsume(QUEUENAME,false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.err.println("张飞正接收到的消息："+new String(body));
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
